import org.jtrace.Hit;
import org.jtrace.Jay;
import org.jtrace.Materials;
import org.jtrace.Scene;
import org.jtrace.Tracer;
import org.jtrace.ViewPlane;
import org.jtrace.cameras.Camera;
import org.jtrace.cameras.PinHoleCamera;
import org.jtrace.geometry.*;
import org.jtrace.lights.Light;
import org.jtrace.listeners.ImageListener;
import org.jtrace.listeners.TimeListener;
import org.jtrace.primitives.*;
import org.jtrace.shader.Shaders;

import bsh.classpath.BshClassPath.JarClassSource;


public class Main {
	public static void main(String[] args) {
		final ViewPlane viewPlane = new ViewPlane(1920, 1080);

        final Point3D lookAt = Point3D.ORIGIN;
        final Point3D eye = new Point3D(0, 0, 100);
        final Vector3D up = new Vector3D(0, 1, 0);
        
        final Camera pinHoleCamera = new PinHoleCamera(eye, lookAt, up);
        pinHoleCamera.setZoomFactor(10);

        final Point3D lightPosition = new Point3D(0, 20, -10);
        final Light light = new Light(lightPosition);

        //final Point3D planePoint = new Point3D(0, -10.1, 0);
        //final Vector3D planeNormal = new Vector3D(0, 1, 0);
       // final Plane lowerPlane = new Plane(planePoint, planeNormal, Materials.metallic(ColorRGB.WHITE));
       // final Plane upperPlane = new Plane(new Point3D(0, 30, 0), planeNormal.multiply(-1), Materials.metallic(ColorRGB.BLACK));
        
        final Sphere sphereBlue = new Sphere(new Point3D(-5, 0, 0), 10, Materials.metallic(ColorRGB.BLUE));
        final Sphere sphereRed = new Sphere(new Point3D(5, 0, 0), 10, Materials.metallic(ColorRGB.RED));
        
        int i = 0;
        while(i < 100){
        	final Point3D rayOrigin = Point3D.ORIGIN;
        	final Vector3D rayDirection = new Vector3D(i, i, i);

        	final Jay jay = new Jay(rayOrigin, rayDirection);  

        	Hit hitBlue = sphereBlue.hit(jay);
        	Hit hitRed = sphereRed.hit(jay);

        	if(hitBlue.isHit() && hitRed.isHit()){
        		if(hitBlue.getT() < hitRed.getT()){
        			System.out.println("Blue " + hitBlue.getPoint(jay));
        		}else{
        			System.out.println("Red " + hitRed.getPoint(jay));
        		}
        		
        	}
        	
        	
        	i++;
        }
        
        //final Scene scene = new Scene().add(sphereBlue,sphereRed, lowerPlane, upperPlane).add(light).setCamera(pinHoleCamera);
        final Scene scene = new Scene().add(sphereBlue,sphereRed).add(light).setCamera(pinHoleCamera);

        final Tracer tracer = new Tracer();

        tracer.addListeners(new ImageListener("Dojo.png", "png"), new TimeListener());
        tracer.addShaders(Shaders.ambientShader(), Shaders.diffuseShader(), Shaders.specularShader(4));

        tracer.render(scene, viewPlane);

	}

}

